data segment 
	a dw 3000 dup(?)
	n dw 3000
data ends

code segment
main proc far
	assume cs:code,ds:data
start:
	push ds
	sub ax,ax
	push ax
	mov ax,data
	mov ds,ax

	call time 	;time 1
	call produce	;produce data
	mov cx,n
	call sort	;sort data
	call time	;time 2
	ret

main endp

sort proc near		;sort function
	mov si,cx
	dec cx
	cmp cx,0
	jz quit
	mov bx,0	
	
beginsort:
	mov ax,a[bx]
	cmp ax,a[bx+2]
	jge continue

	xchg ax,a[bx+2]
	mov a[bx],ax

continue:
	add bx,2
	loop beginsort

	mov cx,si
	dec cx
	call sort
quit:
	ret
sort endp

print proc near		;print function
	mov ah,0
	mov cl,10d
	div cl
	mov dl,al
	mov dh,ah

	add dl,30h
	mov ah,2
	int 21h

	mov dl,dh

	add dl,30h
	mov ah,2
	int 21h

	ret
print endp

time proc near		;time function
	mov ah,2ch
	int 21h	
	push dx

	mov al,cl
	call print

	mov dl,3ah
	mov ah,2h
	int 21h
	
	mov al,dh
	call print

	mov dl,3ah
	mov ah,2h
	int 21h
	
	pop dx
	mov al,dl
	call print
	
	mov dl,30h
	mov ah,2h
	int 21h

	mov dl,0dh
	mov ah,2h
	int 21h

	mov dl,0ah
	mov ah,2
	int 21h
	ret
time endp

produce proc near	;produce function
	mov cx,n
	mov si,0
beginproduce:
	mov a[si],cx
	add si,2
	loop beginproduce
	ret
produce endp

code ends
	end start
